/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.ui.dataimportwiz;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import who.tmap.bo.Attrs;
import who.tmap.common.TMapException;
import who.tmap.imp.ImportAdapter;
import who.tmap.imp.ImportAdapterException;
import who.tmap.imp.ODBCDSNLessImportAdapter;
import who.tmap.imp.impl.ImportAdapterFactory;
import who.tmap.services.ODBCDSNLessDef;
import who.tmap.services.ODBCDSNLessService;
import who.tmap.ui.util.FileChooserFilter;
import who.tmap.ui.util.MiscUIHelper;
import who.tmap.ui.util.jsorttable.JSortTable;
import who.tmap.ui.util.jsorttable.SortTableModel;
/**
 * @author stl
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class JFrameJDBCODBCImportWizard extends JInternalFrame implements DataImportWizardFrame {
	
    protected Attrs attrs;
    protected ODBCDSNLessService dsnLessService =ODBCDSNLessService.getInstance();
    
    private JInternalFrame thisFrame =this;
     
	private JPanel jContentPane = null;

	private JLabel jLabelTables = null;
	private JPanel jPanel = null;
	private JPanel jPanelTable = null;
	private JTable jTable1 = null;
	private JScrollPane jScrollPane = null;
	private JPanel jPanelMisc = null;
	private DataWizardTableDataModel dataModel =null;
	
	private JComboBox jComboBoxTables = null;
	
	private JButton jButtonRefresh = null;
	private JButton jButtonRefreshTables = null;

	private JLabel jLabelODBCDriver = null;

	private JComboBox jComboBoxODBCDriver = null;
	private JLabel jLabelHost = null;
	private JTextField jTextFieldHost = null;
	private JLabel jLabelServer = null;
	private JTextField jTextFieldServer = null;
	private JLabel jLabelPort = null;
	private JTextField jTextFieldPort = null;
	private JLabel jLabelDatabase = null;
	private JTextField jTextFieldDatabase = null;
	private JButton jButtonDatabase = null;
	private JLabel jLabelUserName = null;
	private JTextField jTextFieldUserName = null;
	private JLabel jLabelPwd = null;
	private JPasswordField jPasswordFieldPwd = null;
	private JLabel jLabelSID = null;
	private JTextField jTextFieldSID = null;
	
	/**
	 * This is the default constructor
	 */
	public JFrameJDBCODBCImportWizard() {
		super();
		initialize();
	}
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		setContentPane(getJContentPane());
		updateUIForSelectedDriver();
		pack();

	}
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private javax.swing.JPanel getJContentPane() {
		if (jContentPane == null) {
			
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());

			jContentPane.add(getJPanel(), BorderLayout.CENTER);
		}
		return jContentPane;
	}
	
	/**
	 * This method initializes jLabelTables
	 * 
	 * @return javax.swing.JLabel
	 */
	private javax.swing.JLabel getJLabelTables() {
		if(jLabelTables == null) {
			jLabelTables = new JLabel();
			jLabelTables.setText("Tables");
		}
		return jLabelTables;
	}
	
	/**
	 * This method initializes jPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private javax.swing.JPanel getJPanel() {
		if(jPanel == null) {
			jPanel = new JPanel();
			
			jPanel.setLayout(new BorderLayout());
			jPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
			
			jPanel.add(getJPanelMisc(), BorderLayout.NORTH);
			jPanel.add(getJPanelTable(), BorderLayout.CENTER);
				
		}
		return jPanel;
	}
	
	private ImportAdapter connectToAdapter() throws TMapException {
        ImportAdapter adapter =(ODBCDSNLessImportAdapter)ImportAdapterFactory.getInstance().getImportAdapter( ImportAdapterFactory.JDBC_ODBC );
        Map<String, String> config =new TreeMap<String, String>();
        config.put( ODBCDSNLessImportAdapter.URL, getConnectionUrl() );
        config.put( ODBCDSNLessImportAdapter.TABLE_NAME, ( getJComboBoxTables().getSelectedItem() != null ) 
        													? getJComboBoxTables().getSelectedItem().toString() 
        													: "" );
        
		String driverName =(String)getJComboBoxODBCDriver().getSelectedItem();
		ODBCDSNLessDef dsnLessDef =dsnLessService.getConfigValue( driverName );
		
		String castString =dsnLessDef.getAttrs().get( ODBCDSNLessService.ODBCProps.CAST_STRING.getName() );
		String useBrackets =dsnLessDef.getAttrs().get( ODBCDSNLessService.ODBCProps.USE_BRACKETS.getName() );      
        
        config.put( ODBCDSNLessImportAdapter.CAST_STRING, Boolean.toString( castString != null ) );
        config.put( ODBCDSNLessImportAdapter.USE_BRACKETS, Boolean.toString( useBrackets != null ) );   
        
        config.put( ODBCDSNLessImportAdapter.DB, getJComboBoxODBCDriver().getSelectedItem().toString());
        config.put( ODBCDSNLessImportAdapter.HOST, getJTextFieldHost().getText());
        config.put( ODBCDSNLessImportAdapter.PORT, getJTextFieldPort().getText());        
        config.put( ODBCDSNLessImportAdapter.SERVER, getJTextFieldServer().getText());        
        config.put( ODBCDSNLessImportAdapter.DB_LOCATION, getJTextFieldDatabase().getText());        
        config.put( ODBCDSNLessImportAdapter.UID, getJTextFieldUserName().getText());        
        config.put( ODBCDSNLessImportAdapter.PWD, new String( getJPasswordFieldPwd().getPassword() ));        
        config.put( ODBCDSNLessImportAdapter.SID, getJTextFieldSID().getText());           
        
        adapter.configure( config );	
        
        adapter.connect();
        
        return adapter;        
	}
	
	private String getDsProperty( Map<String, String> dsProperties, String property ) {
		String prop =dsProperties.get( property );
		
		if ( prop == null ) {
			prop ="";
		}
		
		return prop;
	}
	
	public void populateDsProperties( Map<String, String> dsProperties ) throws Exception {
		
		getJComboBoxODBCDriver().setSelectedItem(getDsProperty( dsProperties, ODBCDSNLessImportAdapter.DB));
		getJTextFieldHost().setText( getDsProperty( dsProperties, ODBCDSNLessImportAdapter.HOST) );
		getJTextFieldPort().setText( getDsProperty( dsProperties, ODBCDSNLessImportAdapter.PORT) );
		getJTextFieldServer().setText( getDsProperty( dsProperties, ODBCDSNLessImportAdapter.SERVER) );
		getJTextFieldDatabase().setText( getDsProperty( dsProperties, ODBCDSNLessImportAdapter.DB_LOCATION) );	
		getJTextFieldUserName().setText( getDsProperty( dsProperties, ODBCDSNLessImportAdapter.UID) );
		getJPasswordFieldPwd().setText( getDsProperty( dsProperties, ODBCDSNLessImportAdapter.PWD) );
		getJTextFieldSID().setText( getDsProperty( dsProperties, ODBCDSNLessImportAdapter.SID) );
		getJComboBoxTables().setSelectedItem( getDsProperty( dsProperties, ODBCDSNLessImportAdapter.TABLE_NAME ) );
		
		populateSampleData();
	}
	
	@SuppressWarnings("unchecked")
	public void populateTables() throws TMapException {
        ODBCDSNLessImportAdapter adapter =null;
        Exception e2 =null;
        
        try {
            adapter =(ODBCDSNLessImportAdapter)connectToAdapter();            
            Set tables =adapter.getTables();
            
            jComboBoxTables.removeAllItems();
            
            Iterator it =tables.iterator();
            while( it.hasNext() ) {
                jComboBoxTables.addItem( (String)it.next() );
            }
            
        } catch( Exception e ) {
            e2 =e;
        } finally {
            if ( adapter != null ) {
                try {
                    adapter.disconnect();
                } catch( Exception e3 ) {
                    
                }
            }
        }
        
        if ( e2 != null ) {
            throw new ImportAdapterException( e2 );            
        }
	}
	
	public void populateSampleData() throws TMapException {
		if ( jComboBoxTables.getSelectedIndex() == -1 ) {
			return;
		}
		
        ImportAdapter adapter =connectToAdapter();
        
        try {
            attrs =adapter.readSampleData();
            dataModel.setAttrs( attrs );
            dataModel.fireTableStructureChanged();
            
        } catch( Exception e ) {
            throw new TMapException( e );
        } finally {
            adapter.disconnect();
        }
	}
	
	public Attrs getTable() {
	    return attrs;
	}

	/**
	 * This method initializes jPanelTable	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanelTable() {
		if (jPanelTable == null) {
			GridLayout gridLayout4 = new GridLayout(1,1);
			jPanelTable = new JPanel();
			jPanelTable.setLayout(gridLayout4);
			jPanelTable.setBorder(javax.swing.BorderFactory.createEmptyBorder(5,5,5,5));
			jPanelTable.add(getJScrollPane(), null);
		}
		return jPanelTable;
	}
	/**
	 * This method initializes jTable1	
	 * 	
	 * @return javax.swing.JTable	
	 */    
	private JTable getJTable1() {
		if (jTable1 == null) {
			
			dataModel = new DataWizardTableDataModel();

			jTable1 =new JSortTable( (SortTableModel)dataModel );
		} 
		return jTable1;
	}
	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */    
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJTable1());
		}
		return jScrollPane;
	}
	/**
	 * This method initializes jPanelMisc	
	 * 	
	 * @return javax.swing.JPanel	
	 */    
	private JPanel getJPanelMisc() {
		if (jPanelMisc == null) {

			GridLayout gridLayout = new GridLayout( 9, 3 );

			jPanelMisc = new JPanel( gridLayout );
			gridLayout.setHgap(5);
			gridLayout.setVgap(5);
			jPanelMisc.setBorder(javax.swing.BorderFactory.createEmptyBorder(5,5,5,5));
			
			jLabelODBCDriver = new JLabel();
			jLabelODBCDriver.setText("ODBC Database");			
			jPanelMisc.add(jLabelODBCDriver, null);
			jPanelMisc.add(getJComboBoxODBCDriver(), null);
			jPanelMisc.add(getJButtonRefreshTables(), null);
		
			jLabelHost = new JLabel();
			jLabelHost.setText("Host");			
			jPanelMisc.add(jLabelHost, null);
			jPanelMisc.add(getJTextFieldHost(), null);
			jPanelMisc.add( new JLabel() );
			
			jLabelPort = new JLabel();
			jLabelPort.setText("Port");	
			jPanelMisc.add(jLabelPort, null);
			jPanelMisc.add(getJTextFieldPort(), null);			
			jPanelMisc.add( new JLabel() );
			
			jLabelServer = new JLabel();
			jLabelServer.setText("Server");			
			jPanelMisc.add(jLabelServer, null);
			jPanelMisc.add(getJTextFieldServer(), null);
			jPanelMisc.add( new JLabel() );		
			
			jLabelDatabase = new JLabel();
			jLabelDatabase.setText("Database");			
			jPanelMisc.add(jLabelDatabase, null);
			jPanelMisc.add(getJTextFieldDatabase(), null);
			jPanelMisc.add(getJButtonDatabase(), null);

			jLabelUserName = new JLabel();
			jLabelUserName.setText("User name");			
			jPanelMisc.add(jLabelUserName, null);
			jPanelMisc.add(getJTextFieldUserName(), null);
			jPanelMisc.add( new JLabel() );				

			jLabelPwd = new JLabel();
			jLabelPwd.setText("Password");			
			jPanelMisc.add(jLabelPwd, null);
			jPanelMisc.add(getJPasswordFieldPwd(), null);
			jPanelMisc.add( new JLabel() );				
			
			jLabelSID = new JLabel();
			jLabelSID.setText("SID");			
			jPanelMisc.add(jLabelSID, null);
			jPanelMisc.add(getJTextFieldSID(), null);
			jPanelMisc.add( new JLabel() );				
			
			jPanelMisc.add(getJLabelTables(), null);
			jPanelMisc.add(getJComboBoxTables(), null);
			jPanelMisc.add(getJButtonRefresh(), null);
		}
		return jPanelMisc;
	}
	
	/**
	 * This method initializes jComboBoxTables	
	 * 	
	 * @return javax.swing.JComboBox	
	 */    
	private JComboBox getJComboBoxTables() {
		if (jComboBoxTables == null) {
			jComboBoxTables = new JComboBox();
			jComboBoxTables.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				    try {
                        populateSampleData();
                    } catch (TMapException e1) {
                        new MiscUIHelper().displayErrorMessage( thisFrame, e1 );
                    }				
                }
			});

		}
		return jComboBoxTables;
	}
	
	/**
	 * This method initializes jButtonRefresh	
	 * 	
	 * @return javax.swing.JButton	
	 */    
	private JButton getJButtonRefresh() {
		if (jButtonRefresh == null) {
			jButtonRefresh = new JButton();
			jButtonRefresh.setText("Refresh sample data");
			jButtonRefresh.addActionListener(new ActionListener() { 
				public void actionPerformed(ActionEvent e) {    
				    try {
                        populateSampleData();
                    } catch (TMapException e1) {
                        new MiscUIHelper().displayErrorMessage( thisFrame, e1 );
                    }
				}
			});
		}
		return jButtonRefresh;
	}
	
	public Attrs getValuesTable() throws TMapException {
	    Attrs table =null;
	    ImportAdapter adapter =connectToAdapter();
        
        try {
            table =adapter.readValues();
           
        } catch( Exception e ) {
            throw new TMapException( e );
        } finally {
            if ( adapter != null ) {
                adapter.disconnect();
            }
        }
        
        return table;
	}
	
	/**
	 * This method initializes jButtonRefreshTables	
	 * 	
	 * @return javax.swing.JButton	
	 */    
	private JButton getJButtonRefreshTables() {
		if (jButtonRefreshTables == null) {
			jButtonRefreshTables = new JButton();
			jButtonRefreshTables.setText("Refresh tables");
			jButtonRefreshTables.addActionListener(new ActionListener() { 
				public void actionPerformed(ActionEvent e) {    
				    try {
                        populateTables();
                    } catch (TMapException e1) {
                        new MiscUIHelper().displayErrorMessage( thisFrame, e1 );
                    }
				}
			});
		}
		return jButtonRefreshTables;
	}
	
	/**
	 * This method initializes jComboBoxODBCDriver	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	public JComboBox getJComboBoxODBCDriver() {
		if (jComboBoxODBCDriver == null) {
			jComboBoxODBCDriver = new JComboBox( dsnLessService.getConfigKeys() );
			jComboBoxODBCDriver.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					updateUIForSelectedDriver();
				}
			});
		}
		return jComboBoxODBCDriver;
	}
	
	/**
	 * This method initializes jTextFieldHost	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldHost() {
		if (jTextFieldHost == null) {
			jTextFieldHost = new JTextField();
		}
		return jTextFieldHost;
	}
	
	/**
	 * This method initializes jTextFieldServer	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldServer() {
		if (jTextFieldServer == null) {
			jTextFieldServer = new JTextField();
		}
		return jTextFieldServer;
	}
	
	/**
	 * This method initializes jTextFieldPort	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldPort() {
		if (jTextFieldPort == null) {
			jTextFieldPort = new JTextField();
		}
		return jTextFieldPort;
	}
	
	/**
	 * This method initializes jTextFieldDatabase	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getJTextFieldDatabase() {
		if (jTextFieldDatabase == null) {
			jTextFieldDatabase = new JTextField();
		}
		return jTextFieldDatabase;
	}
	/**
	 * This method initializes jButtonDatabase	
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getJButtonDatabase() {
		if (jButtonDatabase == null) {
			jButtonDatabase = new JButton();
			jButtonDatabase.setText("Browse...");
			jButtonDatabase.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					File file =selectFile();
					if ( file != null ) {
						getJTextFieldDatabase().setText( file.getAbsolutePath() );
					}
				}
			});
		}
		return jButtonDatabase;
	}
	/**
	 * This method initializes jTextFieldUserName	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldUserName() {
		if (jTextFieldUserName == null) {
			jTextFieldUserName = new JTextField();
		}
		return jTextFieldUserName;
	}
	/**
	 * This method initializes jPasswordFieldPwd	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordFieldPwd() {
		if (jPasswordFieldPwd == null) {
			jPasswordFieldPwd = new JPasswordField();
		}
		return jPasswordFieldPwd;
	}
	/**
	 * This method initializes jTextFieldSID	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldSID() {
		if (jTextFieldSID == null) {
			jTextFieldSID = new JTextField();
		}
		return jTextFieldSID;
	}
	
	/**
	 * Hide all the ODBC widgets
	 *
	 */
	private void hideODBCWidgets() {
		jLabelHost.setEnabled( false );
		getJTextFieldHost().setEnabled( false );
		
		jLabelPort.setEnabled( false );
		getJTextFieldPort().setEnabled( false );
		
		jLabelServer.setEnabled( false );
		getJTextFieldServer().setEnabled( false );
		
		jLabelDatabase.setEnabled( false );
		getJTextFieldDatabase().setEnabled( false );
		getJButtonDatabase().setEnabled( false );
		
		jLabelUserName.setEnabled( false );
		getJTextFieldUserName().setEnabled( false );
		
		jLabelPwd.setEnabled( false );
		getJPasswordFieldPwd().setEnabled( false );
		
		jLabelSID.setEnabled( false );
		getJTextFieldSID().setEnabled( false );
		
	}
	
	private void updateUIForSelectedDriver() {
		String driverName =(String)getJComboBoxODBCDriver().getSelectedItem();
		ODBCDSNLessDef dsnLessDef =dsnLessService.getConfigValue( driverName );
		
		hideODBCWidgets();
		
		for( String str : dsnLessDef.getAttrs().keySet() ) {
			if ( ODBCDSNLessService.ODBCProps.HOST.getName().equals( str ) ) {
				jLabelHost.setEnabled( true );
				jLabelHost.setText( "Host" );
				getJTextFieldHost().setEnabled( true );
			} else if ( ODBCDSNLessService.ODBCProps.PORT.getName().equals( str ) ) {
				jLabelPort.setEnabled( true );
				getJTextFieldPort().setEnabled( true );
			} else if ( ODBCDSNLessService.ODBCProps.HOST_PORT.getName().equals( str ) ) {
				jLabelHost.setEnabled( true );
				jLabelHost.setText( "Host, port" );
				getJTextFieldHost().setEnabled( true );			
			} else if ( ODBCDSNLessService.ODBCProps.SERVER.getName().equals( str ) ) {
				jLabelServer.setEnabled( true );
				getJTextFieldServer().setEnabled( true );
			} else if ( ODBCDSNLessService.ODBCProps.DB.getName().equals( str ) ) {
				jLabelDatabase.setEnabled( true );
				getJTextFieldDatabase().setEnabled( true );
			} else if ( ODBCDSNLessService.ODBCProps.DB_LOCATION.getName().equals( str ) ) {
				jLabelDatabase.setEnabled( true );
				getJTextFieldDatabase().setEnabled( true );
				getJButtonDatabase().setEnabled( true );
			} else if ( ODBCDSNLessService.ODBCProps.UID.getName().equals( str ) ) {
				jLabelUserName.setEnabled( true );
				getJTextFieldUserName().setEnabled( true );
			} else if ( ODBCDSNLessService.ODBCProps.PWD.getName().equals( str ) ) {
				jLabelPwd.setEnabled( true );
				getJPasswordFieldPwd().setEnabled( true );
			} else if ( ODBCDSNLessService.ODBCProps.SID.getName().equals( str ) ) {
				jLabelSID.setEnabled( true );
				getJTextFieldSID().setEnabled( true );
			}
		}
		
	}
	
	private String getConnectionUrl() {
		String driverName =(String)getJComboBoxODBCDriver().getSelectedItem();
		Map<String, String> values =buildValueMapFromUI();
		
		String connStr =dsnLessService.getConnectionString( driverName, values );
		
		return connStr;
	}
	
	private Map<String, String> buildValueMapFromUI() {
		Map<String, String> values =new TreeMap<String, String>();
		
		String driverName =(String)getJComboBoxODBCDriver().getSelectedItem();
		ODBCDSNLessDef dsnLessDef =dsnLessService.getConfigValue( driverName );		
		
		for( String str : dsnLessDef.getAttrs().keySet() ) {
			if ( ODBCDSNLessService.ODBCProps.HOST.getName().equals( str ) ) {
				values.put( str, getJTextFieldHost().getText() );
			} else if ( ODBCDSNLessService.ODBCProps.PORT.getName().equals( str ) ) {
				values.put( str, getJTextFieldPort().getText() );
			} else if ( ODBCDSNLessService.ODBCProps.HOST_PORT.getName().equals( str ) ) {
				values.put( str, getJTextFieldHost().getText() );
			} else if ( ODBCDSNLessService.ODBCProps.SERVER.getName().equals( str ) ) {
				values.put( str, getJTextFieldServer().getText() );
			} else if ( ODBCDSNLessService.ODBCProps.DB.getName().equals( str ) ) {
				values.put( str, getJTextFieldDatabase().getText() );
			} else if ( ODBCDSNLessService.ODBCProps.DB_LOCATION.getName().equals( str ) ) {
				values.put( str, getJTextFieldDatabase().getText() );
			} else if ( ODBCDSNLessService.ODBCProps.UID.getName().equals( str ) ) {
				values.put( str, getJTextFieldUserName().getText() );
			} else if ( ODBCDSNLessService.ODBCProps.PWD.getName().equals( str ) ) {
				values.put( str, String.valueOf( getJPasswordFieldPwd().getPassword() ) );
			} else if ( ODBCDSNLessService.ODBCProps.SID.getName().equals( str ) ) {
				values.put( str, getJTextFieldSID().getText() );
			}
		}		
		
		return values;
	}
	
	private File selectFile() {
		File file =null;
		JFileChooser fileChooser = new JFileChooser();
		
		String driverName =(String)getJComboBoxODBCDriver().getSelectedItem();
		ODBCDSNLessDef dsnLessDef =dsnLessService.getConfigValue( driverName );
		String ext =dsnLessDef.getAttrs().get( ODBCDSNLessService.ODBCProps.EXT.getName() );
		
		fileChooser.addChoosableFileFilter( new FileChooserFilter( ext ) );
		
		fileChooser.setCurrentDirectory( FileChooserFilter.DATA_DIR );
		
		// Open file dialog.
		int retVal =fileChooser.showOpenDialog(	this );
		
		if ( retVal == JFileChooser.APPROVE_OPTION ) {		
			file =fileChooser.getSelectedFile();		    
		}

		return file;
	}

   }  //  @jve:decl-index=0:visual-constraint="10,36"
